package com.bing.habit.controller.admin;

import com.bing.habit.entity.IconCategory;
import com.bing.habit.model.result.Result;
import com.bing.habit.model.result.ResultFactory;
import com.bing.habit.service.IconCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/icon_category")
public class IconCategoryController {

    @Autowired
    IconCategoryService iconCategoryService;

    /**
     * 新增/更新 图标分类
     */
    @PostMapping
    public Result addOrUpdate(@RequestBody IconCategory iconCategory) {
        iconCategoryService.addOrUpdate(iconCategory);
        return ResultFactory.buildSuccessResult("添加图标分类成功");
    }

    /**
     * 删除
     */
    @DeleteMapping("/{iconCategoryId}")
    public Result delete(@PathVariable("iconCategoryId") int iconCategoryId) {
        iconCategoryService.delete(iconCategoryId);
        return ResultFactory.buildSuccessResult("删除图标分类成功");
    }

    /**
     * 根据id获取
     */
    @GetMapping("/{iconCategoryId}")
    public Result get(@PathVariable("iconCategoryId") int iconCategoryId) {
        return null;
    }

    /**
     * 返回图标列表
     */
    @GetMapping("/list")
    public Result list() {
        List<IconCategory> iconCategories = iconCategoryService.list();
        return ResultFactory.buildSuccessResult(iconCategories);
    }

}
